<%= render :partial => 'spree/admin/shared/order_tabs', :locals => { :current => 'Return Authorizations' } %>

<% content_for :page_actions do %>
  <% if @order.shipments.any? &:shipped? %>
    <li>
      <% if can? :create, Spree::ReturnAuthorization %>
        <%= button_link_to Spree.t(:new_return_authorization), new_admin_order_return_authorization_url(@order) %>
      <% end %>
    </li>
  <% end %>
<% end %>

<% admin_breadcrumb(plural_resource_name(Spree::ReturnAuthorization)) %>


<% if @order.shipments.any?(&:shipped?) || @order.return_authorizations.any? %>
  <table class="index">
    <thead data-hook="rma_header">
      <tr>
        <th><%= Spree::ReturnAuthorization.human_attribute_name(:number) %></th>
        <th><%= Spree::ReturnAuthorization.human_attribute_name(:state) %></th>
        <th><%= Spree::ReturnAuthorization.human_attribute_name(:pre_tax_total) %></th>
        <th><%= Spree::ReturnAuthorization.human_attribute_name(:created_at) %></th>
        <th class="actions"></th>
      </tr>
    </thead>
    <tbody>
      <% @return_authorizations.each do |return_authorization| %>
        <tr id="<%= spree_dom_id(return_authorization) %>" data-hook="rma_row" class="<%= cycle('odd', 'even')%>">
          <td><%= return_authorization.number %></td>
          <td><%= Spree.t(return_authorization.state.downcase) %></td>
          <td><%= return_authorization.display_pre_tax_total.to_html %></td>
          <td><%= pretty_time(return_authorization.created_at) %></td>
          <td class="actions">
            <% if can? :update, return_authorization %>
              <%= link_to_edit return_authorization, :no_text => true, :class => 'edit' %>
            <% end %>
            <% if can?(:destroy, return_authorization) && !return_authorization.customer_returned_items? %>
              <%= link_to_delete return_authorization, :no_text => true %>
            <% end %>
          </td>
        </tr>
      <% end %>
    </tbody>
  </table>
<% else %>
  <div data-hook="rma_cannot_create" class="no-objects-found">
    <%= Spree.t(:cannot_create_returns) %>
  </div>
<% end %>
